package com.fg.ihr.domain;

import lombok.Data;
import org.springframework.format.annotation.NumberFormat;
import sun.security.util.Password;

import javax.persistence.*;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import java.util.Set;


@Entity
@Table(name="user")
public class User {

    @ManyToMany(cascade = {CascadeType.REFRESH},fetch = FetchType.EAGER)
    @JoinTable( name="user_roles", joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "roles_id"))
    private List<Role> roles;

    public User() {
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    private Integer id;
    //用户名字
    @Column(length = 32)
    private String name;
    //用户密码
    @Column(length = 100)
    private String password;
    //登录名
    @Column(length = 32,unique = true)
    private String username;
    //身份证号码
//    @Size(min = 13, max = 20, message = "身份证长度必须在{min}和{max}之间")
    @Column(length = 32)
    private String idnumber;
    //护士注册证号码
//    @Size(min = 13, max = 20, message = "护士注册证号码必须在{min}和{max}之间")
    @Column(length = 32)
    private String regnumber;
    //工号
//    @Size(min = 13, max = 20, message = "工号必须在{min}和{max}之间")
    @Column(length = 32)
    private String worknumber;
    @Past
    //出生年月
    @Temporal(TemporalType.DATE)
    private Date birthday;
    //入职日期
    @Past
    @Temporal(TemporalType.DATE)
    private Date regdate;
    //手机号码
//    @NotNull(message = "电话号码不能为空")
//    @Size(min = 13, max = 20, message = "工号必须在{min}和{max}之间")
    @Column(length = 64)
    private String phonenumber;
    //银行卡号
//    @NotNull(message = "银行卡号不能为空")
    @Column(length = 64,unique = true)
    private String bankaccount;
    //性别
//    @AssertTrue(message = "性别不能为空")
    private Boolean sex;
    //科室
//    @AssertTrue(message = "病房未选")
    @ManyToOne
    private Ward ward;
    //职级
//    @AssertTrue(message = "职级未选")
    @ManyToOne
    private Level level;
    //职称
//    @AssertTrue(message = "职称未选")
    @ManyToOne
    private Title title;
    //状态
    @ManyToOne
    private Status status;

    private boolean is_delete;
    //职位
    @ManyToMany(cascade=CascadeType.MERGE,fetch=FetchType.LAZY)
    @JoinTable(name="user_position",
            joinColumns={@JoinColumn(name="user_id")},
            inverseJoinColumns={@JoinColumn(name="position_id")})
    private List<Position> positionList;
    //初始学历
    @ManyToOne
    private Education education;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getIdnumber() {
        return idnumber;
    }

    public void setIdnumber(String idnumber) {
        this.idnumber = idnumber;
    }

    public String getRegnumber() {
        return regnumber;
    }

    public void setRegnumber(String regnumber) {
        this.regnumber = regnumber;
    }

    public String getWorknumber() {
        return worknumber;
    }

    public void setWorknumber(String worknumber) {
        this.worknumber = worknumber;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhonenumber() {
        return phonenumber;
    }

    public Date getRegdate() {
        return regdate;
    }

    public void setRegdate(Date regdate) {
        this.regdate = regdate;
    }

    public void setPhonenumber(String phonenumber) {
        this.phonenumber = phonenumber;
    }

    public String getBankaccount() {
        return bankaccount;
    }

    public void setBankaccount(String bankaccount) {
        this.bankaccount = bankaccount;
    }

    public Boolean getSex() {
        return sex;
    }

    public void setSex(Boolean sex) {
        this.sex = sex;
    }

    public Ward getWard() {
        return ward;
    }

    public void setWard(Ward ward) {
        this.ward = ward;
    }

    public Level getLevel() {
        return level;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    public Title getTitle() {
        return title;
    }

    public void setTitle(Title title) {
        this.title = title;
    }

    public Status getStatus() {
        return status;
    }

    public boolean isIs_delete() {
        return is_delete;
    }

    public void setIs_delete(boolean is_delete) {
        this.is_delete = is_delete;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Education getEducation() {
        return education;
    }

    public void setEducation(Education education) {
        this.education = education;
    }

    public List<Position> getPositionList() {
        return positionList;
    }

    public void setPositionList(List<Position> positionList) {
        this.positionList = positionList;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }


}